package com.javaee.my.business;

import com.javaee.interceptor.entity.Shopping_Cart;
import com.javaee.my.user.BaseControllerApi;
import org.apache.ibatis.session.ResultHandler;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
//展示购物车中的数据
@WebServlet("/display")
public class displayGoods_msgController extends HttpServlet implements BaseControllerApi {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        Integer id= (Integer) session.getAttribute("id");//从session中获取用户的id
        //查询用户购物车中的商品以及其最终总价格
        List<Shopping_Cart> Shopping_Cartlist=sqlsession.selectList(
                "com.javaee.my.dao.businessMapper.select_Shopping_cartBy_id",id);
        float finalAllPrice=sqlsession.selectOne("com.javaee.my.dao.businessMapper.select_Shopping_cart_allprice",id);
        session.setAttribute("Shopping_Cartlist",Shopping_Cartlist);
        session.setAttribute("finalAllPrice",finalAllPrice);
        req.getRequestDispatcher("shopping_cart.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
